import { $http } from '@/utils';
import { $ResponseCode } from '@/utils/const/env';
export const Address = {
    saveAddress: (data: any) => {
        return new Promise((resolve, reject) => {
            $http.post('Address/saveAddress', { data }).then((res: any) => {
                if (res.code === $ResponseCode.SUCCESS) {
                    resolve(res);
                } else {
                    reject(res);
                }
            }).catch(() => {
                reject({ msg: '服务器繁忙，请稍后再试' });
            })
        })
    },
    getAddressDetails: (id: any) => {
        return new Promise((resolve, reject) => {
            $http.get('Address/getAddressDetails', {
                data: {
                    id
                }
            }).then((res: any) => {
                if (res.code === $ResponseCode.SUCCESS) {
                    resolve(res.data);
                } else {
                    reject(res);
                }
            }).catch(() => {
                reject({ msg: '服务器繁忙，请稍后再试' });
            })
        })
    },
    getAddress: () => {
        return new Promise((resolve, reject) => {
            $http.get('Address/getAddress').then((res: any) => {
                if (res.code === $ResponseCode.SUCCESS) {
                    resolve(res.data);
                } else {
                    reject(res);
                }
            }).catch(() => {
                reject({ msg: '服务器繁忙，请稍后再试' });
            })
        })
    },
    deleteAddress: (data: any) => {
        return new Promise((resolve, reject) => {
            $http.post('Address/deleteAddress', { data }).then((res: any) => {
                if (res.code === $ResponseCode.SUCCESS) {
                    resolve(res);
                } else {
                    reject(res);
                }
            }).catch(() => {
                reject({ msg: '服务器繁忙，请稍后再试' });
            })
        })
    }
};